{% extends 'base.html' %}
{% block title %}药品类型{% endblock %}

{% block head %}
{{ super() }}
<style>
.medicine-types-container {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin: 0;
    padding: 30px;
}
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}
.page-title {
    font-size: 2rem;
    font-weight: 400;
    color: #333;
    margin: 0;
}
.btn-add-type {
    padding: 0.5rem 1rem;
    background-color: #28a745;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    transition: background-color 0.3s ease;
}
.btn-add-type:hover {
    background-color: #218838;
    color: white;
    text-decoration: none;
}
.search-box {
    margin-bottom: 20px;
}
.search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 1rem;
}
.search-input:focus {
    border-color: #4a90e2;
    outline: none;
    box-shadow: 0 0 0 0.2rem rgba(74,144,226,0.25);
}
.types-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.types-table th,
.types-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e9ecef;
}
.types-table th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: #495057;
}
.types-table tbody tr:hover {
    background-color: #f8f9fa;
}
</style>
{% endblock %}

{% block content %}
<div class="medicine-types-container">
    <div class="page-header">
        <h2 class="page-title">药品类型管理</h2>
        <a href="{{ url_for('add_medicine_type') }}" class="btn-add-type">
            <i class="fas fa-plus"></i> 添加类型
        </a>
    </div>
    <div class="search-box">
        <input type="text" class="search-input" id="typeSearch" placeholder="搜索类型名称..." onkeyup="searchTypes()">
    </div>
    <table class="types-table">
        <thead>
            <tr>
                <th>ID</th>
                <th>名称</th>
                <th>描述</th>
            </tr>
        </thead>
        <tbody>
            {% for type in types %}
            <tr>
                <td>{{ type['类型ID'] }}</td>
                <td>{{ type['类型名称'] }}</td>
                <td>{{ type['描述'] }}</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
<script>
function searchTypes() {
    const input = document.getElementById('typeSearch');
    const filter = input.value.toLowerCase();
    const tbody = document.querySelector('.types-table tbody');
    const rows = tbody.getElementsByTagName('tr');
    for (let row of rows) {
        const nameCell = row.getElementsByTagName('td')[1];
        if (nameCell) {
            const name = nameCell.textContent || nameCell.innerText;
            if (name.toLowerCase().indexOf(filter) > -1) {
                row.style.display = '';
            } else {
                row.style.display = 'none';
            }
        }
    }
}
</script>
{% endblock %}
